﻿using System;
using Resn.WhuPub.BLL;
using Resn.WhuPub.DAL;
using Resn.WhuPub.DML;
using System.Linq;
using System.Collections.Generic;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 实现专业设置的属性和方法
        /// </summary>
        public class MajorSetup : Entity<MajorSetupModel>
        {
                #region 构造函数

                /// <summary>
                /// 创建专业设置实例
                /// </summary>
                /// <param name="model">专业设置模型</param>
                public MajorSetup(MajorSetupModel model)
                        : base(model)
                {
                }
                #endregion

                #region 属性

                #region 基本属性

                

                /// <summary>
                /// 获取专业设置的院系Id
                /// </summary>
                /// <value>
                /// 专业设置的院系Id
                /// </value>
                public string DepartmentId
                {
                        get
                        {
                                return Model.DepartmentId;
                        }
                }

                /// <summary>
                /// 获取专业设置的专业Id
                /// </summary>
                /// <value>
                /// 专业Id
                /// </value>
                public string MajorId
                {
                        get
                        {
                                return Model.MajorId;
                        }
                }

                /// <summary>
                /// 获取或设置专业负责人的姓名
                /// </summary>
                /// <value>
                /// 专业负责人的姓名
                /// </value>
                public string ManagerName
                {
                        get
                        {
                                return Model.ManagerName;
                        }
                        set
                        {
                                Model.ManagerName = value;
                        }
                }

                /// <summary>
                /// 获取或设置专业教学负责人的姓名
                /// </summary>
                /// <value>
                /// 专业教学负责人的姓名
                /// </value>
                public string TeachingManagerName
                {
                        get
                        {
                                return Model.TeachingManagerName;
                        }
                        set
                        {
                                Model.TeachingManagerName = value;
                        }
                }

                

                #endregion 基本属性

                

                /// <summary>
                /// 获取开设该专业的院\系\处\所
                /// </summary>
                /// <value>
                /// 开设该专业的院\系\处\所
                /// </value>
                public Department Department
                {
                        get
                        {
                                var model = DBStorage.Instance.Select<DepartmentModel>(DepartmentId);
                                return new Department(model);
                        }
                }

                /// <summary>
                /// 获取专业设置的专业分类信息
                /// </summary>
                /// <value>
                /// 专业设置的专业分类信息
                /// </value>
                public Major Major
                {
                        get
                        {
                                var model = DBStorage.Instance.Select<MajorModel>(MajorId);
                                return new Major(model);
                        }
                }

                /// <summary>
                /// 获取专业设置下属的历年专业招生信息
                /// </summary>
                /// <value>
                /// 专业设置下属的历年专业招生信息
                /// </value>
                public List<MajorOperation> MajorOperations
                {
                        get
                        {
                                var models = DBStorage.Instance.Select<MajorOperationModel>().Where(i => i.MajorSetupId == Id).ToList();

                                var result = new List<MajorOperation>();

                                models.ForEach(i => result.Add(new MajorOperation(i)));

                                return result;
                        }
                }

                #endregion 属性

                #region 方法

                /// <summary>
                /// 获取指定标识的对象
                /// </summary>
                /// <param name="id">标识</param>
                /// <returns></returns>
                public static MajorSetup Select(string id)
                {
                        return Select<MajorSetup>(id);
                }
                /// <summary>
                /// 创建专业招生信息
                /// </summary>
                /// <param name="year">年份</param>
                /// <param name="studentsAmount">招生人数</param>
                /// <returns>
                /// 创建的专业招生信息对象
                /// </returns>
                public MajorOperation CreateMajorOperation(int year, int studentsAmount)
                {
                        var model = new MajorOperationModel
                                {
                                        Id = Guid.NewGuid().ToString(),
                                        MajorSetupId = Id,
                                        Year = year,
                                        StudentsAmount = studentsAmount
                                };

                        return  new MajorOperation(model);
                }

                
                #endregion 方法
        }
}